<template>
  <div class="app-container">
    <el-form ref="form" :model="book" label-width="80px">
      <el-form-item label="书名">
        <el-input v-model="book.bookName"  style="width: 217px;" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="作者">
        <el-input v-model="book.author"  style="width: 217px;" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="简介">
        <el-input v-model="book.introduce"  style="width: 217px;" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="类别">
        <el-input v-model="book.category"  style="width: 217px;" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="会员">
        <el-select v-model="state" placeholder="用户性别" :disabled="true">
          <el-option
            v-for="item in options"
            :key="item.state"
            :label="item.label"
            :value="item.state">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="头像">
        <!--     图片 "'api'+user.path"  -->
<!--        <template slot-scope="scope">-->
<!--          <img :src="'/api'+scope.row.path" width="60px" height="60px">-->
<!--        </template>-->
        <el-image
          style="width: 100px; height: 100px"
          :src="'/api'+this.book.path"
        ></el-image>
      </el-form-item>

      <!--      帮我写一个消息框-->
      <el-form-item label="章节目录">

      </el-form-item>
    </el-form>

    <el-table :data="chapters" border style="width:100%"
              stripe>

      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="100">
      </el-table-column>

      <el-table-column
        prop="bookName"
        label="书名"
        width="480"
        align="center">
      </el-table-column>


      <el-table-column
        prop="chapter"
        label="章节"
        width="480"
        align="center">
      </el-table-column>

<!--      <el-table-column-->
<!--        prop="messages"-->
<!--        label="消息"-->
<!--        align="center"-->
<!--        width="400">-->
<!--      </el-table-column>-->



    </el-table>





  </div>
</template>


<script>
import axios from "axios";

export default {
  name: "UserMoneyView",
  data() {
    return {
      total: 0,
      pageInfo: {
        pageNum: 1,
        pageSize: 5,
        bookName:"",

      },
      book: {
        bookShelfId:0,
        bookName:'',
        author:'',
        introduce:'',
        category:'',
        path:'',
        vip:0,
      },
      // options:[],
      category:"",
      user:{
        id:'',
        username:'',
      },
      options: [{
        // value: '选项1',
        label: '普通书籍',
        state: '1',
      }, {
        // value: '选项2',
        label: 'vip书籍',
        state: '2',
      } ],
      state: '',
      //总的章节管理
      chapters:[],



    }

  },
  // 前置执行方法在执行之前    beforeCreate()   axios.post(get)("http://localhost:8080/queryAll").then(...)
  created() { // 这是可以获取data中的数据后  再执行下面的axios
    this.getData()
  },
  methods: {
    sta(row) {
      if (row.vip == 1) {
        return '普通书籍'
      } else {
        return 'Vip书籍'
      }
    },
    // 修改书籍
    // handleEdit(index, row) {
    //   alert(row.id)
    //   // 使用路由的push方法  跳转到修改书籍页面
    //   this.$router.push({ name: 'BookEditView', query: { id: row.id }})
    // },


    // 修改每页条数
    handleSizeChange(val) {
      this.pageInfo.pageSize = val
      this.getData()
    },
    // 修改当前页数
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val
      this.getData()
    },
    // 获取数据
    getData() {
      this.book.bookShelfId=parseInt(this.$route.query.id)

        axios({
          //获取所有的用户的信息和他们的角色信息
          url: '/api/bookshelf/queryAllByBookShelfId/'+this.book.bookShelfId,
          method: 'post',
          headers:{"Authorization":"Bearer "+this.$store.state.user.token}
        }).then(res => {
          // console.log(res.data.data)
          // this.money=res.data.data.list
          this.book=res.data.data
          if(res.data.data.vip==1){
            this.state='普通书籍'
          }else if (res.data.data.vip==2){
            this.state='Vip书籍'
          }
          // console.log(this.role)
          // for (const arr in this.role) {
          //     this.role.name=this.role[arr].roleList.name
          // }
          this.total = res.data.data.total
        })

      //根据bookshelfId 查询表 b_bs表的 bookid  /bookshelf/queryBookIdByBsid/{bsId}
      axios({
        url: '/api/bookshelf/queryBookIdByBsid/'+this.book.bookShelfId,
        method: 'post',
        headers:{"Authorization":"Bearer "+this.$store.state.user.token}
      }).then(res => {
        // console.log(res.data.data)
        //根据bookid  查询数组 chapids  根据chapids  查询表chapters
        //根据书籍的id查询b_chap表  /book/queryChapids/{bookId}
          axios({
            url: '/api/book/queryChapids/'+res.data.data,
            method: 'post',
            headers:{"Authorization":"Bearer "+this.$store.state.user.token}
          }).then(res => {
            console.log(res.data.data)
            this.chapters=res.data.data

          })


      })




      // //根据用户名查询到所有的用户信息
      // var formData = new FormData();
      // formData.append("username", this.$store.state.user.name)
      // axios({
      //   //根据用户名查询用户的个人信息
      //   url: '/api/user/queryUser',
      //   method: 'post',
      //   data: formData,
      //   headers:{"Authorization":"Bearer "+this.$store.state.user.token}
      // }).then(res => {
      //   console.log(res.data.data.id)
      //
      //
      //
      //
      // })










    },
    // 查询
    onSubmit() {
      // alert(this.pageInfo.username)
      this.pageInfo.pageNum = 1 // 点击查询时  页码重置为1
      this.getData()
    },

    // 删除书架信息
    handleDelete(index, row) {
      // get post

      if (confirm('确定要删除吗')) {
        axios({
          url: '/api/bookshelf/delete/' + row.id,
          method: 'post',
          headers:{"Authorization":"Bearer "+this.$store.state.user.token}
        }).then(res => {
          if (res.data.code == 1) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            // 更新本页数据
            this.getData()
          } else {
            this.$message.error('删除失败')
          }
        })
      }
    }
    // this.$router.push({name:})
  }


}
</script>

<style scoped>

</style>
